package com.dt76.smallloanbackendservice.service.etao.impl;

import com.dt76.smallloanbackendservice.mapper.etao.SLogMapper;
import com.dt76.smallloanbackendservice.pojo.etao.SLog;
import com.dt76.smallloanbackendservice.service.etao.SLogService;
import com.dt76.smallloanbackendservice.utils.DateUtils;
import com.dt76.smallloanbackendservice.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SLogServiceImpl implements SLogService {

    @Autowired
    private SLogMapper sLogMapper;


    @Override
    public Page getSLog(Integer pageNum, Integer eId, String startTime) {
        Page page = new Page();
        page.setPageIndex(pageNum);
        page.setTotalCount(sLogMapper.getAllCount(eId, startTime));
        List<SLog> sLogs = sLogMapper.selectSLog((page.getPageIndex() - 1) * page.getPageSize(),
                page.getPageSize(),
                eId, startTime);
        for (SLog sLog : sLogs) {
            sLog.setTimeStr(DateUtils.dateToString(sLog.getLogTime(),"yyyy-MM-dd HH:mm:ss"));
        }
        page.setRows(sLogs);
        return page;
    }

    @Override
    public boolean deelByTime(String delTime) {
        boolean fg = false;
        int i = sLogMapper.delByTime(delTime);
        if (i == 1) {
            fg = true;
        }
        return fg;
    }



}
